package com.ziyia.a4_1_3;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import java.io.Serializable;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void startActivity(View view) {
        Intent intent = new Intent(this, MainActivity2.class);
        startActivity(intent);

    }


    public void startActivityForResult(View view) {
        Intent intent = new Intent(this, MainActivity2.class);
        startActivityForResult(intent, 200);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 200) {

            String username = data.getStringExtra("username");

            new AlertDialog.Builder(this)
                    .setTitle("当前Activity：" + getLocalClassName() + "，接收到数据")
                    .setMessage(username)
                    .create()
                    .show();
        }
    }



    public void BundleTest(View view) {
        User user = new User(1, "root", "root", "root@qq.com");

        Bundle bundle = new Bundle();
        bundle.putSerializable("user", user);

        Intent intent = new Intent(this, MainActivity2.class);
        intent.putExtras(bundle);

        startActivity(intent);

    }
}